package model.location;

import java.util.Arrays;

import net.sourceforge.zbar.Symbol;
import android.util.Log;

import com.google.zxing.Result;
import com.google.zxing.ResultPoint;

public class ReferencePointFactory 
{
	public static ReferencePoint createReferencePoint(Result result)
	{
		ResultPoint[] resultPoints = result.getResultPoints();		
		
		int width = (int) (resultPoints[2].getX() - resultPoints[1].getX());
		int height = (int) (resultPoints[0].getY() - resultPoints[1].getY());
		
		int x = (int) (resultPoints[1].getX() + (width / 2));
		int y = (int) (resultPoints[1].getY() + (height / 2));
		
		Log.d("QR", String.format("Location code(%s) - {%d;%d}", result.toString(), x, y));
		return new ReferencePoint(result.toString(), x, y, resultPoints);
	}
	
	public static ReferencePoint createReferencePoint(Symbol symbol)
	{
		int[] bounds = symbol.getBounds();
		
		int x = bounds[0];
		int y = bounds[1];
		
		Log.d("Symbol", String.format("bounds code(%s) - %s}", symbol.getData(), Arrays.toString(bounds)));
		return new ReferencePoint(symbol.getData(), x, y, symbol.getBounds());
	}
}
